package com.hudson.broker.handler.process;

import com.hudson.broker.handler.Process;
import com.hudson.broker.config.BrokerConfig;
import com.hudson.codec.domain.RemotingCommand;
import com.hudson.common.domain.meta.TopicQueueMap;
import com.hudson.common.enums.MessageTypeEnum;
import com.hudson.core.json.JSONUtil;
import com.hudson.store.queue.QueueNumUtil;
import io.netty.channel.ChannelHandlerContext;

import java.nio.charset.StandardCharsets;

public class QueueMapProcesser implements Process {
    @Override
    public RemotingCommand process(ChannelHandlerContext context, RemotingCommand remotingCommand) {

        return RemotingCommand.builder().type(MessageTypeEnum.QUEUE_MAP.getType())
                .body(JSONUtil.toJson(new TopicQueueMap(BrokerConfig.BROKER_NAME, QueueNumUtil.getMap())).getBytes(StandardCharsets.UTF_8))
                .build();
    }
}
